@extends('admin.admin')

@section('style')
    <link href="{{ asset('dist/lib/fileinput/css/fileinput.min.css') }}" rel="stylesheet">
@endsection

@section('content')
    <div class="main animsition">
        <div class="container-fluid">
            <div class="row">
                <div class="">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <h3 class="panel-title">编辑轮播图</h3>
                        </div>
                        <div class="panel-body">
                            <form class="form-horizontal" role="form" method="POST"
                                  action="{{ url('admin/grid/edit_post') }}">
                                <input type="hidden" name="_token" value="{{ csrf_token() }}">
                                <input type="hidden" name="id" value="{{ $data['id'] }}">
                                @include('admin.grid._form')
                                <div class="form-group">
                                    <div class="col-md-7 col-md-offset-3">
                                        <button type="submit" class="btn btn-primary btn-md">
                                            <i class="fa fa-plus-circle"></i>
                                            保存
                                        </button>
                                    </div>
                                </div>

                            </form>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@stop

@section('script')
    <script type="text/javascript" src="{{ asset('dist/lib/fileinput/js/fileinput.min.js') }}"></script>
    <script type="text/javascript" src="{{ asset('dist/lib/fileinput/js/fileinput_locale_zh.js') }}"></script>

    <script type="text/javascript">
        var img = new Array();
        var imgConfig = new Array();
        img = @if(!empty($data['img']))["<img src='{!! $data['img'] !!}' class='file-preview-image'>"];
        @else '';
        @endif
            imgConfig = @if(!empty($data['img']))[{url: "{{ url('admin/delimg')}}", key: "{{$data['img']}}"}];
        @else '';
        @endif
        $("#input-24").fileinput({
            // allowedFileExtensions : ['jpg', 'png','gif'],
            showCaption: false,
            showPreview: true,
            showRemove: true,
            showUpload: true,
            showCancel: true,
            maxFileSize: 2048,
            maxFileCount: 1,
            minFileCount: 1,
            uploadUrl: "{{ url('admin/upload_img') }}",
            dropZoneTitle: "此处可拖拽",
            initialPreview: img,
            initialPreviewConfig: imgConfig,
        }).on('filedeleted', function (outData) {
            $('input[name=img]').val('');
        }).on("fileuploaded", function (event, outData) {
            //文件上传成功后返回的数据， 此处我只保存返回文件的id
            var result = outData.response.url;
            // 对应的input 赋值
            $('input[name=img]').val(result);
        });
    </script>

@endsection